<?php
namespace app\sadmin\controller;
use \think\Controller;
use \think\Db;
class Sadminlog extends Controller
{
public function Sadminlog(){
        //调用模型层，实现获取用户列表数据的功能
        //$videos=Db::name("videos")->select();
        $sadmin=Db::name("sadmin")->select();
        $this->assign("sadmin",$sadmin);
        return $this->fetch();
        
    }

     



        public function login(){
        if (request()->isPOST()) {
            
            
                 //验证失败
              
                
                    //验证管理员账号密码
                    $a = input('sadmin');
                    $p = input('spassword');
                    $sadmin=Db::name("sadmin")->where('sadminname',$a)->find();
                    if (!$sadmin) {
                        echo "<script>alert('账号不存在！');</script>";

                    }else if ($p!=$sadmin['sadminpwd']) {
                        echo "<script>alert('密码错误!');</script>";
                    }
                    else {
                            \think\Session::set('user',$a);
                            \think\Session::set('userid',$sadmin['sadminid']);
                            $this->redirect('club/club');


                    }
                    //SQL:select * from admin where adminname  = '$a' 
                    //正确，把账号和id保存到session中 ，跳转到视频列表
                    //错误，用户名不存在
                    //密码错误；
                    
                

        } 
        return $this->fetch();
    }

}